﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0074)mhtml:file://E:\sve-air\documentacion\RSA Cryptography - Crypto++ Wiki.mht -->
<HTML lang=en dir=ltr><HEAD><TITLE>RSA Cryptography - Crypto++ Wiki</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="MSHTML 6.00.6000.17080" name=GENERATOR><LINK 
href="/wiki/RSA_Cryptography" rel=canonical><LINK href="/favicon.ico" 
rel="shortcut icon"><LINK title="Crypto++ Wiki (en)" 
href="/w/opensearch_desc.php" type=application/opensearchdescription+xml 
rel=search><LINK title="Crypto++ Wiki Atom feed" 
href="/w/index.php?title=Special:RecentChanges&amp;feed=atom" 
type=application/atom+xml rel=alternate><LINK media=screen 
href="RSA%20Cryptography%20-%20Crypto++%20Wiki_archivos/shared.css" 
rel=stylesheet><LINK media=print 
href="RSA%20Cryptography%20-%20Crypto++%20Wiki_archivos/commonPrint.css" 
rel=stylesheet><LINK media=screen 
href="RSA%20Cryptography%20-%20Crypto++%20Wiki_archivos/main.css" 
rel=stylesheet><!--[if lt IE 5.5000]><link rel="stylesheet" href="/w/skins/monobook/IE50Fixes.css?270" media="screen" /><![endif]--><!--[if IE 5.5000]><link rel="stylesheet" href="/w/skins/monobook/IE55Fixes.css?270" media="screen" /><![endif]--><!--[if IE 6]><link rel="stylesheet" href="/w/skins/monobook/IE60Fixes.css?270" media="screen" /><![endif]--><!--[if IE 7]><LINK 
media=screen 
href="RSA%20Cryptography%20-%20Crypto++%20Wiki_archivos/IE70Fixes.css" 
rel=stylesheet><![endif]--><LINK 
href="/w/index.php?title=MediaWiki:Common.css&amp;usemsgcache=yes&amp;ctype=text%2Fcss&amp;smaxage=18000&amp;action=raw&amp;maxage=18000" 
rel=stylesheet><LINK media=print 
href="/w/index.php?title=MediaWiki:Print.css&amp;usemsgcache=yes&amp;ctype=text%2Fcss&amp;smaxage=18000&amp;action=raw&amp;maxage=18000" 
rel=stylesheet><LINK 
href="/w/index.php?title=MediaWiki:Monobook.css&amp;usemsgcache=yes&amp;ctype=text%2Fcss&amp;smaxage=18000&amp;action=raw&amp;maxage=18000" 
rel=stylesheet><LINK 
href="RSA%20Cryptography%20-%20Crypto++%20Wiki_archivos/index.css" 
rel=stylesheet>
<SCRIPT>
var skin="monobook",
stylepath="/w/skins",
wgUrlProtocols="http\\:\\/\\/|https\\:\\/\\/|ftp\\:\\/\\/|irc\\:\\/\\/|gopher\\:\\/\\/|telnet\\:\\/\\/|nntp\\:\\/\\/|worldwind\\:\\/\\/|mailto\\:|news\\:|svn\\:\\/\\/",
wgArticlePath="/wiki/$1",
wgScriptPath="/w",
wgScriptExtension=".php",
wgScript="/w/index.php",
wgVariantArticlePath=false,
wgActionPaths={},
wgServer="http://www.cryptopp.com",
wgCanonicalNamespace="",
wgCanonicalSpecialPageName=false,
wgNamespaceNumber=0,
wgPageName="RSA_Cryptography",
wgTitle="RSA Cryptography",
wgAction="view",
wgArticleId=1506,
wgIsArticle=true,
wgUserName=null,
wgUserGroups=null,
wgUserLanguage="en",
wgContentLanguage="en",
wgBreakFrames=false,
wgCurRevisionId=7787,
wgVersion="1.16.0",
wgEnableAPI=true,
wgEnableWriteAPI=true,
wgSeparatorTransformTable=["", ""],
wgDigitTransformTable=["", ""],
wgMainPageTitle="Main Page",
wgFormattedNamespaces={"-2": "Media", "-1": "Special", "0": "", "1": "Talk", "2": "User", "3": "User talk", "4": "Crypto++ Wiki", "5": "Crypto++ Wiki talk", "6": "File", "7": "File talk", "8": "MediaWiki", "9": "MediaWiki talk", "10": "Template", "11": "Template talk", "12": "Help", "13": "Help talk", "14": "Category", "15": "Category talk"},
wgNamespaceIds={"media": -2, "special": -1, "": 0, "talk": 1, "user": 2, "user_talk": 3, "crypto++_wiki": 4, "crypto++_wiki_talk": 5, "file": 6, "file_talk": 7, "mediawiki": 8, "mediawiki_talk": 9, "template": 10, "template_talk": 11, "help": 12, "help_talk": 13, "category": 14, "category_talk": 15, "image": 6, "image_talk": 7},
wgSiteName="Crypto++ Wiki",
wgCategories=["Sample", "Download", "Public Key", "Signature"],
wgRestrictionEdit=[],
wgRestrictionMove=[];
</SCRIPT>

<SCRIPT 
src="RSA%20Cryptography%20-%20Crypto++%20Wiki_archivos/wikibits.js"></SCRIPT>

<SCRIPT 
src="RSA%20Cryptography%20-%20Crypto++%20Wiki_archivos/ajax.js"></SCRIPT>

<SCRIPT 
src="RSA%20Cryptography%20-%20Crypto++%20Wiki_archivos/index.php"></SCRIPT>
</HEAD>
<BODY class="mediawiki ltr ns-0 ns-subject page-RSA_Cryptography skin-monobook">
<DIV id=globalWrapper>
<DIV id=column-content>
<DIV id=content><A id=top></A>
<H1 class=firstHeading id=firstHeading>RSA Cryptography</H1>
<DIV id=bodyContent>
<H3 id=siteSub>From Crypto++ Wiki</H3>
<DIV id=contentSub>(Redirected from <A title=RSA 
href="http://www.cryptopp.com/w/index.php?title=RSA&amp;redirect=no">RSA</A>)</DIV>
<DIV id=jump-to-nav>Jump to: <A 
href="http://www.cryptopp.com/wiki/RSA#column-one">navigation</A>, <A 
href="http://www.cryptopp.com/wiki/RSA#searchInput">search</A></DIV><!-- start content -->
<P>RSA is the work of Ron Rivest, Adi Shamir, and Leonard Adleman. It is based 
on the Integer Factorization Problem. The system was developed in 1977 and 
patented by the Massachusetts Institute of Technology. Though Rivest, Shamir, 
and Adleman are generally credited with the discovery, Clifford Cocks (Chief 
Mathematician at GCHQ - the British equivalent of the NSA) described the system 
in 1973. However, Cocks did not publish since the work was considered 
classified, so the credit lay with Rivest, Shamir, and Adleman. </P>
<TABLE class=toc id=toc>
  <TBODY>
  <TR>
    <TD>
      <DIV id=toctitle>
      <H2>Contents</H2></DIV>
      <UL>
        <LI class="toclevel-1 tocsection-1"><A 
        href="http://www.cryptopp.com/wiki/RSA#Background"><SPAN 
        class=tocnumber>1</SPAN> <SPAN class=toctext>Background</SPAN></A> 
        <UL>
          <LI class="toclevel-2 tocsection-2"><A 
          href="http://www.cryptopp.com/wiki/RSA#Keys"><SPAN 
          class=tocnumber>1.1</SPAN> <SPAN class=toctext>Keys</SPAN></A> 
          <LI class="toclevel-2 tocsection-3"><A 
          href="http://www.cryptopp.com/wiki/RSA#Encryption_Schemes"><SPAN 
          class=tocnumber>1.2</SPAN> <SPAN class=toctext>Encryption 
          Schemes</SPAN></A> 
          <LI class="toclevel-2 tocsection-4"><A 
          href="http://www.cryptopp.com/wiki/RSA#Signature_Schemes"><SPAN 
          class=tocnumber>1.3</SPAN> <SPAN class=toctext>Signature 
          Schemes</SPAN></A> </LI></UL>
        <LI class="toclevel-1 tocsection-5"><A 
        href="http://www.cryptopp.com/wiki/RSA#Sample_Programs"><SPAN 
        class=tocnumber>2</SPAN> <SPAN class=toctext>Sample Programs</SPAN></A> 
        <UL>
          <LI class="toclevel-2 tocsection-6"><A 
          href="http://www.cryptopp.com/wiki/RSA#Key_Generation"><SPAN 
          class=tocnumber>2.1</SPAN> <SPAN class=toctext>Key 
          Generation</SPAN></A> 
          <LI class="toclevel-2 tocsection-7"><A 
          href="http://www.cryptopp.com/wiki/RSA#RSA_Encryption_Scheme_.28OAEP_using_SHA.29"><SPAN 
          class=tocnumber>2.2</SPAN> <SPAN class=toctext>RSA Encryption Scheme 
          (OAEP using SHA)</SPAN></A> 
          <LI class="toclevel-2 tocsection-8"><A 
          href="http://www.cryptopp.com/wiki/RSA#RSA_Signature_Scheme_.28PKCS_v1.5.29"><SPAN 
          class=tocnumber>2.3</SPAN> <SPAN class=toctext>RSA Signature Scheme 
          (PKCS v1.5)</SPAN></A> </LI></UL>
        <LI class="toclevel-1 tocsection-9"><A 
        href="http://www.cryptopp.com/wiki/RSA#Downloads"><SPAN 
        class=tocnumber>3</SPAN> <SPAN class=toctext>Downloads</SPAN></A> 
        <UL>
          <LI class="toclevel-2 tocsection-10"><A 
          href="http://www.cryptopp.com/wiki/RSA#Additional_Downloads"><SPAN 
          class=tocnumber>3.1</SPAN> <SPAN class=toctext>Additional 
          Downloads</SPAN></A> </LI></UL></LI></UL></TD></TR></TBODY></TABLE>
<SCRIPT>if (window.showTocToggle) { var tocShowText = "show"; var tocHideText = "hide"; showTocToggle(); } </SCRIPT>

<H2><SPAN class=mw-headline id=Background>Background </SPAN></H2>
<P>Crypto++ exposes most <A class=mw-redirect title=RSA 
href="mhtml:file://E:\sve-air\documentacion\RSA Cryptography - Crypto++ Wiki.mht!http://www.cryptopp.com/wiki/RSA">RSA</A> 
encrpytion and signatures operations through <TT>rsa.h</TT> and <TT>pssr.h</TT>. 
The following will discuss some of the finer details of Crypto++, <A 
class=mw-redirect title=RSA 
href="mhtml:file://E:\sve-air\documentacion\RSA Cryptography - Crypto++ Wiki.mht!http://www.cryptopp.com/wiki/RSA">RSA</A> 
keys, <A title="RSA Encryption Schemes" 
href="http://www.cryptopp.com/wiki/RSA_Encryption_Schemes">RSA encryption 
schemes</A>, and <A title="RSA Signature Schemes" 
href="http://www.cryptopp.com/wiki/RSA_Signature_Schemes">RSA signature 
schemes</A>. If interested in directly performing exponentiation using RSA 
primitives, see <A title="Raw RSA" 
href="http://www.cryptopp.com/wiki/Raw_RSA">Raw RSA</A>. </P>
<H3><SPAN class=mw-headline id=Keys>Keys </SPAN></H3>
<P>Operations on keys, such as generating, validating, loading, saving, 
importing, exporting, and formats are discussed in detail at <A 
title="Keys and Formats" 
href="http://www.cryptopp.com/wiki/Keys_and_Formats">Keys and Formats</A>. </P>
<P>Crypto++ <A class=mw-redirect title=RSA 
href="mhtml:file://E:\sve-air\documentacion\RSA Cryptography - Crypto++ Wiki.mht!http://www.cryptopp.com/wiki/RSA">RSA</A> 
keys are typedef'd in <TT>rsa.h</TT> as follows. </P><PRE>struct RSA
{
    typedef RSAFunction PublicKey;
    typedef InvertibleRSAFunction PrivateKey;
};</PRE>
<P>To generate a key pair, <TT>InvertibleRSAFunction</TT> offers 
<TT>GenerateRandomWithKeySize</TT>: </P><PRE>GenerateRandomWithKeySize (RandomNumberGenerator &amp;rng, unsigned int keySize)</PRE>
<P>The parameters to the function are a <TT><A title=RandomNumberGenerator 
href="http://www.cryptopp.com/wiki/RandomNumberGenerator">RandomNumberGenerator</A></TT> 
and the modulus size specified in bits. <TT>GenerateRandomWithKeySize</TT> calls 
<TT>GenerateRandom</TT> with the modulus size encoded as a 
<TT>NameValuePairs</TT>. </P>
<P>In much of the sample code, <TT>InvertibleRSAFunction</TT> is used as follows 
to create a logical separation for demonstration purposes. </P><PRE>///////////////////////////////////////
// Generate Parameters
InvertibleRSAFunction params;
params.GenerateRandomWithKeySize(rng, 3072);

///////////////////////////////////////
// Create Keys
RSA::PrivateKey privateKey(params);
RSA::PublicKey publicKey(params);</PRE>
<P>In practice, <TT>RSA::PrivateKey</TT> could be used instead of 
<TT>InvertibleRSAFunction</TT> (to improve readability); and 
<TT>RSAES_PKCS1v15_Encryptor</TT>, <TT>RSAES_OAEP_SHA_Encryptor</TT>, and 
friends should be used. A more detailed treatment of keys, generation, loading, 
saving, and formats can be found at <A title="Keys and Formats" 
href="http://www.cryptopp.com/wiki/Keys_and_Formats">Keys and Formats</A>. </P><PRE>///////////////////////////////////////
// Create Keys
RSA::PrivateKey privateKey;
privateKey.GenerateRandomWithKeySize(rng, 3072);

RSA::PublicKey publicKey(privateKey);</PRE>
<P>Once the keys are created, they can be passed to Encryptors, Decryptors, 
Signers, and Verifiers. </P>
<P>To persist the keys to disk in the most inter-operable manner, use the 
<TT>Save</TT> function. If loading from disk, use the <TT>Load</TT> function. A 
more complete treatment of saving and loading keys is covered in <A 
title="Keys and Formats" 
href="http://www.cryptopp.com/wiki/Keys_and_Formats">Keys and Formats</A>. </P>
<P>If you have a RSA private key composed of {n,e,d} and are interested in 
calculating all parameters specified in PKCS #1, see <A class="external text" 
href="http://groups.google.com/group/sci.crypt/browse_frm/thread/d228e099f78164e3">RSA 
CRT key?</A> on sci.crypt. In addition, Mounir Idrassi offers an open source 
tool at Sourceforge: <A class="external text" 
href="http://rsaconverter.sourceforge.net/">RSA Converter</A>. </P>
<P>If you need to import the {n,e,d} private key or {n,e} public key into 
Crypto++, use <TT>Initialize</TT>. Both <TT>RSA::PublicKey</TT> and 
<TT>RSA::PrivateKey</TT> provide the function overloads. </P>
<H3><SPAN class=mw-headline id=Encryption_Schemes>Encryption Schemes 
</SPAN></H3>
<P>The high level <A title="RSA Encryption Schemes" 
href="http://www.cryptopp.com/wiki/RSA_Encryption_Schemes">RSA encryption 
schemes</A> are exposed through <TT>RSAES</TT>, which is defined as follows. The 
template parameter, <TT>STANDARD</TT>, simply specifies additional algorithms. 
For example, when <A class=new title="PKCS (page does not exist)" 
href="http://www.cryptopp.com/w/index.php?title=PKCS&amp;action=edit&amp;redlink=1">PKCS</A> 
processing is required, <TT>PKCS1v15</TT> is specified as the parameter. </P><PRE>template &lt;class STANDARD&gt;
struct RSAES&nbsp;: public TF_ES&lt;STANDARD, RSA&gt;
{ };</PRE>
<P>The <TT>TF_ES</TT> class exposes the functionality that is often used when 
working with <A class=mw-redirect title=RSA 
href="mhtml:file://E:\sve-air\documentacion\RSA Cryptography - Crypto++ Wiki.mht!http://www.cryptopp.com/wiki/RSA">RSA</A>. 
<B>TF</B> stands for trapdoor function, and <B>ES</B> stands for encryption 
scheme. There is some hand waiving here - at least two layers of templates exist 
before encountering <TT>TF_EncryptorBase</TT> and <TT>TF_DecryptorBase</TT> in 
<TT>cryptlib.h</TT>. To ease use of the library, two typedefs are offered. The 
first is based on PKCS #1 version 1.5, and the second is based on <A class=new 
title="OAEP (page does not exist)" 
href="http://www.cryptopp.com/w/index.php?title=OAEP&amp;action=edit&amp;redlink=1">OAEP</A> 
and <A title=SHA href="http://www.cryptopp.com/wiki/SHA">SHA</A>. </P><PRE>typedef RSAES&lt;PKCS1v15&gt;::Decryptor RSAES_PKCS1v15_Decryptor;
typedef RSAES&lt;PKCS1v15&gt;::Encryptor RSAES_PKCS1v15_Encryptor;

typedef RSAES&lt;OAEP&lt;SHA&gt; &gt;::Decryptor RSAES_OAEP_SHA_Decryptor;
typedef RSAES&lt;OAEP&lt;SHA&gt; &gt;::Encryptor RSAES_OAEP_SHA_Encryptor;</PRE>
<H3><SPAN class=mw-headline id=Signature_Schemes>Signature Schemes </SPAN></H3>
<P>The high level <A title="RSA Signature Schemes" 
href="http://www.cryptopp.com/wiki/RSA_Signature_Schemes">RSA signature 
schemes</A> are exposed through <TT>RSASS</TT>, which is defined as follows. 
</P><PRE>template &lt;class STANDARD, class H&gt;
struct RSASS&nbsp;: public TF_SS&lt;STANDARD, H, RSA&gt;
{ };</PRE>
<P>As with <TT>RSAES</TT>, <TT>RSASS</TT> needs a <TT>STANDARD</TT>. <B>TF</B> 
stands for trapdoor function, and <B>SS</B> stands for signature scheme. In 
addition to the <TT>STANDARD</TT> parameter, a one way hash function must be 
specified through <TT>H</TT>. The classes of interest for signers and verifiers 
are <TT><A class=new title="PK Signer (page does not exist)" 
href="http://www.cryptopp.com/w/index.php?title=PK_Signer&amp;action=edit&amp;redlink=1">PK_Signer</A></TT> 
and <TT><A class=new title="PK Verifier (page does not exist)" 
href="http://www.cryptopp.com/w/index.php?title=PK_Verifier&amp;action=edit&amp;redlink=1">PK_Verifier</A></TT> 
from <TT>cryptlib.h</TT>. The later classes offer familiar functions such as 
<TT>MaxSignatureLength</TT>, <TT>SignMessage</TT>, and <TT>VerifyMessage</TT>. 
</P>
<P>The Crypto++ <A class=mw-redirect title=RSA 
href="mhtml:file://E:\sve-air\documentacion\RSA Cryptography - Crypto++ Wiki.mht!http://www.cryptopp.com/wiki/RSA">RSA</A> 
implementation of a <A title="Digital Signature" 
href="http://www.cryptopp.com/wiki/Digital_Signature">Signature Scheme with 
Appendix</A> (SSA) is typedef'd as follows. Note that two additional hashes are 
specified in PKCS (<A class=new title="MD2 (page does not exist)" 
href="http://www.cryptopp.com/w/index.php?title=MD2&amp;action=edit&amp;redlink=1">MD2</A> 
and <A class=new title="MD5 (page does not exist)" 
href="http://www.cryptopp.com/w/index.php?title=MD5&amp;action=edit&amp;redlink=1">MD5</A>), 
but should not be used. </P><PRE>typedef RSASS&lt;PKCS1v15, SHA&gt;::Signer RSASSA_PKCS1v15_SHA_Signer;
typedef RSASS&lt;PKCS1v15, SHA&gt;::Verifier RSASSA_PKCS1v15_SHA_Verifier;</PRE>
<P>The Crypto++ <A class=mw-redirect title=RSA 
href="mhtml:file://E:\sve-air\documentacion\RSA Cryptography - Crypto++ Wiki.mht!http://www.cryptopp.com/wiki/RSA">RSA</A> 
implementation of a <A title="Digital Signature" 
href="http://www.cryptopp.com/wiki/Digital_Signature">Signature Scheme with 
Recovery</A> (PSSR) is similar to SSA. However, there are no typedef's so the 
objects are declared using template syntax. Below, <TT>PSSR</TT> (from 
<TT>pssr.h</TT>) is specified (the recovery mechanism), and a hash is specified. 
</P><PRE>RSASS&lt;PSSR, SHA1&gt;::Signer signer;
RSASS&lt;PSSR, SHA1&gt;::Verifier verifier;</PRE>
<P>If Whirlpool were desired, the following would be performed. </P><PRE>RSASS&lt;PSSR, Whirlpool&gt;::Signer signer;
RSASS&lt;PSSR, Whirlpool&gt;::Verifier verifier;</PRE>
<P>For those interested in NIST compliance after 2010, code might need to be 
migrated to the SHA-2 family of hashes. </P><PRE>RSASS&lt;PSSR, SHA256&gt;::Signer signer;
RSASS&lt;PSSR, SHA256&gt;::Verifier verifier;</PRE>
<P>Regardless of the type of signature (PSSR vs SSA), the signers and verifiers 
are most easily constructed using the private key or the public key. </P><PRE>// Generate or Load keys
RSA::PrivateKey privateKey;
RSA::PublicKey publicKey;
...

RSASS&lt;PSSR, SHA1&gt;::Signer signer(privateKey);
// Create signature
...

RSASS&lt;PSSR, SHA1&gt;::Verifier verifier(publicKey);
// Verify signature on message
...</PRE>
<H2><SPAN class=mw-headline id=Sample_Programs>Sample Programs </SPAN></H2>
<P>Due to the number and size of <A class=mw-redirect title=RSA 
href="mhtml:file://E:\sve-air\documentacion\RSA Cryptography - Crypto++ Wiki.mht!http://www.cryptopp.com/wiki/RSA">RSA</A> 
sample programs, two additional pages have been created for <A 
title="RSA Encryption Schemes" 
href="http://www.cryptopp.com/wiki/RSA_Encryption_Schemes">RSA Encryption 
Schemes</A> and <A title="RSA Signature Schemes" 
href="http://www.cryptopp.com/wiki/RSA_Signature_Schemes">RSA Signature 
Schemes</A>. Below, four samples are presented. Additional samples can be found 
at <A title="RSA Encryption Schemes" 
href="http://www.cryptopp.com/wiki/RSA_Encryption_Schemes">RSA Encryption 
Schemes</A> and <A title="RSA Signature Schemes" 
href="http://www.cryptopp.com/wiki/RSA_Signature_Schemes">RSA Signature 
Schemes</A>. </P>
<UL>
  <LI><A class=mw-redirect title=RSA 
  href="mhtml:file://E:\sve-air\documentacion\RSA Cryptography - Crypto++ Wiki.mht!http://www.cryptopp.com/wiki/RSA">RSA</A> 
  Key Generation 
  <LI><A class=mw-redirect title=RSA 
  href="mhtml:file://E:\sve-air\documentacion\RSA Cryptography - Crypto++ Wiki.mht!http://www.cryptopp.com/wiki/RSA">RSA</A> 
  Encryption and Decryption 
  <LI><A class=mw-redirect title=RSA 
  href="mhtml:file://E:\sve-air\documentacion\RSA Cryptography - Crypto++ Wiki.mht!http://www.cryptopp.com/wiki/RSA">RSA</A> 
  Signature and Verification (PKCS v1.5) </LI></UL>
<H3><SPAN class=mw-headline id=Key_Generation>Key Generation </SPAN></H3><PRE>///////////////////////////////////////
// Pseudo Random Number Generator
AutoSeededRandomPool rng;

///////////////////////////////////////
// Generate Parameters
InvertibleRSAFunction params;
params.GenerateRandomWithKeySize(rng, 3072);

///////////////////////////////////////
// Generated Parameters
const Integer&amp; n = params.GetModulus();
const Integer&amp; p = params.GetPrime1();
const Integer&amp; q = params.GetPrime2();
const Integer&amp; d = params.GetPrivateExponent();
const Integer&amp; e = params.GetPublicExponent();

///////////////////////////////////////
// Dump
cout &lt;&lt; "RSA Parameters:" &lt;&lt; endl;
cout &lt;&lt; " n: " &lt;&lt; n &lt;&lt; endl;
cout &lt;&lt; " p: " &lt;&lt; p &lt;&lt; endl;
cout &lt;&lt; " q: " &lt;&lt; q &lt;&lt; endl;
cout &lt;&lt; " d: " &lt;&lt; d &lt;&lt; endl;
cout &lt;&lt; " e: " &lt;&lt; e &lt;&lt; endl;
cout &lt;&lt; endl;

///////////////////////////////////////
// Create Keys
RSA::PrivateKey privateKey(params);
RSA::PublicKey publicKey(params);</PRE>
<H3><SPAN class=mw-headline id=RSA_Encryption_Scheme_.28OAEP_using_SHA.29>RSA 
Encryption Scheme (OAEP using SHA) </SPAN></H3>
<P>The following code demonstrates <A class=mw-redirect title=RSA 
href="mhtml:file://E:\sve-air\documentacion\RSA Cryptography - Crypto++ Wiki.mht!http://www.cryptopp.com/wiki/RSA">RSA</A> 
encryption using OAEP. The complete list of <A class=mw-redirect title=RSA 
href="mhtml:file://E:\sve-air\documentacion\RSA Cryptography - Crypto++ Wiki.mht!http://www.cryptopp.com/wiki/RSA">RSA</A> 
encryption scheme samples can be found at <A title="RSA Encryption Schemes" 
href="http://www.cryptopp.com/wiki/RSA_Encryption_Schemes">RSA Encryption 
Schemes</A>. </P><PRE>////////////////////////////////////////////////
// Generate keys
AutoSeededRandomPool rng;

InvertibleRSAFunction params;
params.GenerateRandomWithKeySize(rng, 3072);

RSA::PrivateKey privateKey(params);
RSA::PublicKey publicKey(params);

string plain="RSA Encryption", cipher, recovered;

////////////////////////////////////////////////
// Encryption
RSAES_OAEP_SHA_Encryptor e(publicKey);

StringSource(plain, true,
    new PK_EncryptorFilter(rng, e,
        new StringSink(cipher)
   ) // PK_EncryptorFilter
); // StringSource

////////////////////////////////////////////////
// Decryption
RSAES_OAEP_SHA_Decryptor d(privateKey);

StringSource(cipher, true,
    new PK_DecryptorFilter(rng, d,
        new StringSink(recovered)
   ) // PK_DecryptorFilter
); // StringSource

cout &lt;&lt; "Recovered plain text" &lt;&lt; endl;</PRE>
<H3><SPAN class=mw-headline id=RSA_Signature_Scheme_.28PKCS_v1.5.29>RSA 
Signature Scheme (PKCS v1.5) </SPAN></H3>
<P>Though similar to RSA-SSA, <TT>RSASSA_PKCS1v15_SHA_Signer</TT> and 
<TT>RSASSA_PKCS1v15_SHA_Verifier</TT> use PKCS v1.5 padding. The <A class=new 
title="MD2 (page does not exist)" 
href="http://www.cryptopp.com/w/index.php?title=MD2&amp;action=edit&amp;redlink=1">MD2</A> 
and <A class=new title="MD5 (page does not exist)" 
href="http://www.cryptopp.com/w/index.php?title=MD5&amp;action=edit&amp;redlink=1">MD5</A> 
variants of <TT>RSASSA_PKCS1v15_&lt;<I>Digest</I>&gt;_Signer</TT> and 
<TT>RSASSA_PKCS1v15_&lt;<I>Digest</I>&gt;_Verifier</TT> <B>should not</B> be 
used. The complete list of <A class=mw-redirect title=RSA 
href="mhtml:file://E:\sve-air\documentacion\RSA Cryptography - Crypto++ Wiki.mht!http://www.cryptopp.com/wiki/RSA">RSA</A> 
signature scheme samples can be found at <A title="RSA Signature Schemes" 
href="http://www.cryptopp.com/wiki/RSA_Signature_Schemes">RSA Signature 
Schemes</A>. </P><PRE>// Generate or Load keys
RSA::PrivateKey privateKey = ...;
RSA::PublicKey publicKey = ...;

// Message
string message = "RSA Signature", signature;

////////////////////////////////////////////////
// Sign and Encode
RSASSA_PKCS1v15_SHA_Signer signer(privateKey);

StringSource(message, true, 
    new SignerFilter(rng, signer,
        new StringSink(signature)
   ) // SignerFilter
); // StringSource

////////////////////////////////////////////////
// Verify and Recover
RSASSA_PKCS1v15_SHA_Verifier verifier(publicKey);

StringSource(message+signature, true,
    new SignatureVerificationFilter(
        verifier, NULL,
        SignatureVerificationFilter::THROW_EXCEPTION
   ) // SignatureVerificationFilter
); // StringSource

cout &lt;&lt; "Verified signature on message" &lt;&lt; endl;</PRE>
<H2><SPAN class=mw-headline id=Downloads>Downloads </SPAN></H2>
<P><A class=internal title=RSA-ES-OAEP-SHA-Filter-Test.zip 
href="http://www.cryptopp.com/w/images/2/23/RSA-ES-OAEP-SHA-Filter-Test.zip">RSA-ES-OAEP-SHA-Filter-Test.zip</A> 
- Demonstrates RSA-ES (OAEP/SHA) using Filters </P>
<P><A class=internal title=RSA-SSA-Filter-Test.zip 
href="http://www.cryptopp.com/w/images/9/9b/RSA-SSA-Filter-Test.zip">RSA-SSA-Filter-Test.zip</A> 
- Demonstrates RSA-SSA using Filters </P>
<P><A class=internal title="Rsa kgen prof.zip" 
href="http://www.cryptopp.com/w/images/d/d0/Rsa_kgen_prof.zip">rsa_kgen_prof.zip</A> 
- Generates a RSA key pair with profiling </P>
<H3><SPAN class=mw-headline id=Additional_Downloads>Additional Downloads 
</SPAN></H3>
<UL>
  <LI><A title="RSA Encryption Schemes" 
  href="http://www.cryptopp.com/wiki/RSA_Encryption_Schemes">RSA Encryption 
  Schemes</A> 
  <LI><A title="RSA Signature Schemes" 
  href="http://www.cryptopp.com/wiki/RSA_Signature_Schemes">RSA Signature 
  Schemes</A> </LI></UL><!-- 
NewPP limit report
Preprocessor node count: 174/1000000
Post-expand include size: 0/2097152 bytes
Template argument size: 0/2097152 bytes
Expensive parser function count: 0/100
--><!-- Saved in parser cache with key crypto-wikicryptopp_:pcache:idhash:1506-0!1!0!!en!2!edit=0 and timestamp 20110217074857 -->
<DIV class=printfooter>Retrieved from "<A 
href="http://www.cryptopp.com/wiki/RSA_Cryptography">http://www.cryptopp.com/wiki/RSA_Cryptography</A>"</DIV>
<DIV class=catlinks id=catlinks>
<DIV id=mw-normal-catlinks><A title=Special:Categories 
href="http://www.cryptopp.com/wiki/Special:Categories">Categories</A>: <SPAN 
dir=ltr><A title=Category:Sample 
href="http://www.cryptopp.com/wiki/Category:Sample">Sample</A></SPAN> | <SPAN 
dir=ltr><A title=Category:Download 
href="http://www.cryptopp.com/wiki/Category:Download">Download</A></SPAN> | 
<SPAN dir=ltr><A title="Category:Public Key" 
href="http://www.cryptopp.com/wiki/Category:Public_Key">Public Key</A></SPAN> | 
<SPAN dir=ltr><A title=Category:Signature 
href="http://www.cryptopp.com/wiki/Category:Signature">Signature</A></SPAN></DIV></DIV><!-- end content -->
<DIV class=visualClear></DIV></DIV></DIV></DIV>
<DIV id=column-one>
<DIV class=portlet id=p-cactions>
<H5>Views</H5>
<DIV class=pBody>
<UL>
  <LI class=selected id=ca-nstab-main><A title="View the content page [c]" 
  accessKey=c href="http://www.cryptopp.com/wiki/RSA_Cryptography">Page</A> 
  <LI class=new id=ca-talk><A title="Discussion about the content page [t]" 
  accessKey=t 
  href="http://www.cryptopp.com/w/index.php?title=Talk:RSA_Cryptography&amp;action=edit&amp;redlink=1">Discussion</A> 

  <LI id=ca-viewsource><A 
  title="This page is protected.&#10;You can view its source [e]" accessKey=e 
  href="http://www.cryptopp.com/w/index.php?title=RSA_Cryptography&amp;action=edit">View 
  source</A> 
  <LI id=ca-history><A title="Past revisions of this page [h]" accessKey=h 
  href="http://www.cryptopp.com/w/index.php?title=RSA_Cryptography&amp;action=history">History</A> 
  </LI></UL></DIV></DIV>
<DIV class=portlet id=p-personal>
<H5>Personal tools</H5>
<DIV class=pBody>
<UL>
  <LI id=pt-login><A 
  title="You are encouraged to log in; however, it is not mandatory [o]" 
  accessKey=o 
  href="http://www.cryptopp.com/w/index.php?title=Special:UserLogin&amp;returnto=RSA_Cryptography">Log 
  in / create account</A> </LI></UL></DIV></DIV>
<DIV class=portlet id=p-logo><A title="Visit the main page" 
style="BACKGROUND-IMAGE: url(http://www.cryptopp.com/w/images/0/0b/Logo-Steel.png)" 
href="http://www.cryptopp.com/wiki/Main_Page"></A></DIV>
<SCRIPT type=text/javascript> if (window.isMSIE55) fixalpha(); </SCRIPT>

<DIV class="generated-sidebar portlet" id=p-navigation>
<H5>Navigation</H5>
<DIV class=pBody>
<UL>
  <LI id=n-mainpage-description><A title="Visit the main page [z]" accessKey=z 
  href="http://www.cryptopp.com/wiki/Main_Page">Main page</A> 
  <LI id=n-portal><A 
  title="About the project, what you can do, where to find things" 
  href="http://www.cryptopp.com/wiki/Crypto++_Wiki:Community_portal">Community 
  portal</A> 
  <LI id=n-currentevents><A 
  title="Find background information on current events" 
  href="http://www.cryptopp.com/wiki/Crypto++_Wiki:Current_events">Current 
  events</A> 
  <LI id=n-recentchanges><A title="The list of recent changes in the wiki [r]" 
  accessKey=r href="http://www.cryptopp.com/wiki/Special:RecentChanges">Recent 
  changes</A> 
  <LI id=n-randompage><A title="Load a random page [x]" accessKey=x 
  href="http://www.cryptopp.com/wiki/Special:Random">Random page</A> 
  <LI id=n-help><A title="The place to find out" 
  href="http://www.cryptopp.com/wiki/Help:Contents">Help</A> 
</LI></UL></DIV></DIV>
<DIV class=portlet id=p-search>
<H5><LABEL for=searchInput>Search</LABEL></H5>
<DIV class=pBody id=searchBody>
<FORM id=searchform action=/w/index.php><INPUT type=hidden value=Special:Search 
name=title> <INPUT id=searchInput title="Search Crypto++ Wiki" accessKey=f 
type=search name=search> <INPUT class=searchButton id=searchGoButton title="Go to a page with this exact name if exists" type=submit value=Go name=go>&nbsp; 
<INPUT class=searchButton id=mw-searchButton title="Search the pages for this text" type=submit value=Search name=fulltext> 
</FORM></DIV></DIV>
<DIV class=portlet id=p-tb>
<H5>Toolbox</H5>
<DIV class=pBody>
<UL>
  <LI id=t-whatlinkshere><A title="List of all wiki pages that link here [j]" 
  accessKey=j 
  href="http://www.cryptopp.com/wiki/Special:WhatLinksHere/RSA_Cryptography">What 
  links here</A> 
  <LI id=t-recentchangeslinked><A 
  title="Recent changes in pages linked from this page [k]" accessKey=k 
  href="http://www.cryptopp.com/wiki/Special:RecentChangesLinked/RSA_Cryptography">Related 
  changes</A> 
  <LI id=t-specialpages><A title="List of all special pages [q]" accessKey=q 
  href="http://www.cryptopp.com/wiki/Special:SpecialPages">Special pages</A> 
  <LI id=t-print><A title="Printable version of this page [p]" accessKey=p 
  href="http://www.cryptopp.com/w/index.php?title=RSA_Cryptography&amp;printable=yes" 
  rel=alternate>Printable version</A> 
  <LI id=t-permalink><A title="Permanent link to this revision of the page" 
  href="http://www.cryptopp.com/w/index.php?title=RSA_Cryptography&amp;oldid=7787">Permanent 
  link</A> </LI></UL></DIV></DIV></DIV><!-- end of the left (by default at least) column -->
<DIV class=visualClear></DIV>
<DIV id=footer>
<DIV id=f-poweredbyico><A href="http://www.mediawiki.org/"><IMG height=31 
alt="Powered by MediaWiki" 
src="RSA%20Cryptography%20-%20Crypto++%20Wiki_archivos/mht1D1(1).tmp" 
width=88></A></DIV>
<UL id=f-list>
  <LI id=lastmod>This page was last modified on 14 February 2011, at 05:38. 
  <LI id=viewcount>This page has been accessed 29,440 times. 
  <LI id=privacy><A title="Crypto++ Wiki:Privacy policy" 
  href="http://www.cryptopp.com/wiki/Crypto++_Wiki:Privacy_policy">Privacy 
  policy</A> 
  <LI id=about><A title="Crypto++ Wiki:About" 
  href="http://www.cryptopp.com/wiki/Crypto++_Wiki:About">About Crypto++ 
  Wiki</A> 
  <LI id=disclaimer><A title="Crypto++ Wiki:General disclaimer" 
  href="http://www.cryptopp.com/wiki/Crypto++_Wiki:General_disclaimer">Disclaimers</A> 
  </LI></UL></DIV></DIV>
<SCRIPT>if (window.runOnloadHook) runOnloadHook();</SCRIPT>
<!-- Served in 0.341 secs. --></BODY></HTML>
